package com.emser.unc.activitys.resources;

import java.util.ArrayList;
import java.util.List;

import com.emser.unc.R;
import com.emser.unc.serializable.CustomerDTO;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
 
public class CustomerAdapter extends ArrayAdapter<CustomerDTO>{
	
    private ArrayList<CustomerDTO> entries;
    private Activity activity;
 
    public CustomerAdapter(Activity a, int textViewResourceId, List<CustomerDTO> values) {
        super(a, textViewResourceId, values);
        this.entries = (ArrayList<CustomerDTO>) values;
        this.activity = a;
    }
 
    public static class ViewHolder{
    	public TextView item0;
        public TextView item1;
        public TextView item2;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        ViewHolder holder;
        if (v == null) {
            LayoutInflater vi =
                (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.r_customer_row_view, null);
            holder = new ViewHolder();
            holder.item0 = (TextView) v.findViewById(R.id.customer_code);
            holder.item1 = (TextView) v.findViewById(R.id.customer_name);
            holder.item2 = (TextView) v.findViewById(R.id.customer_address);
            v.setTag(holder);
        }
        else{
        	holder=(ViewHolder)v.getTag();
        }
        final CustomerDTO custom = entries.get(position);
        if (custom != null) {
        	Long code = custom.getCode();
        	holder.item0.setText(code.toString());
            holder.item1.setText(custom.toString());
            holder.item2.setText(custom.getAddress());
        }
        return v;
    }
 
}